Repository navigation
Run the API project tests in parallel and fix their failures - #10149
Conversation
Run the tests of ProjectTests at the same time. The ones that change the shared test project or backtest, or page the account's project list, stay non parallelizable. Lock the configuration reload, which two fixtures' set-ups can run at once. Fix what made the API Tests workflow fail: - request 6 parallel optimization nodes, the most the api accepts - give each object store test a key of its own instead of a fixed one shared by every concurrent run, and pause between listing polls - rename the project to a second new name instead of back to its first - keep reading the backtest report, and the object store download, until a deadline instead of failing after the client's own poll - wait for a free live node, deploying on it, until a deadline - poll a finished backtest's status until it is the expected one, since the api can report the final statistics first Part of #9967 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Requesting changes.
Description: the Measurements section describes the environment the local runs used. Please edit it to the outcome only (which tests ran, how many runs, what passed and how long they took), not what the environment had or lacked.
1. The object store download retry can outlast the 7-minute hang timeout, and the description says it can't (inline comment). Api.GetObjectStore polls up to 5 minutes for the url on every call (Api/Api.cs:1387). The loop checks its 6-minute deadline only before each call, so a retry that starts at about 5 minutes can run to about 10. --blame-hang-timeout 7minutes is per test, so if the url is still slow, the test host gets killed and the rest of the run is lost. On master the same case fails one assertion at 5 minutes. Since the client's wait can't be shortened without an Api change, the options I see are: raise the hang timeout in api-tests.yml to cover the longest retry (the issue allows a workflow change described in the pull request), or keep the retry only for calls that fail quickly. Either way, the description should give the real worst case.
2. No run of the changed workflow yet. The local runs covered ProjectTests alone, 4 times, with 36 of 38 passing and the 2 report tests explained. Two things haven't run at all: the download cases of GetObjectStoreWorksAsExpected, and the two fixtures together, which is what CI runs and what the expected ~7 minutes is based on. The workflow only runs on push to a branch name without /, so pushing this head commit to a branch named that way runs the real API Tests job before merge. Please add its outcome and time to the description.
What I checked and found sound:
- Parallelism: NUnit runs
NonParallelizabletests in the non-parallel shift, which doesn't overlap the parallel one. I listed every test that touchesTestProject/TestBacktest. The ones that change them (files, nodes, backtest name, tags, note, project rename) are all marked. The rest only read, or create and delete their own project.ObjectStoreTestskeeps running its tests one after another. - The
ReloadConfigurationlock, the new keys under their own folder (so the/CI_TESTdownload cases don't pick them up), the 1 s pause in the delete poll, the status poll for the failing backtest cases,WaitForBacktestReport(ReadBacktestReportsleeps 10 s per request, so the loop doesn't spin), andCreateLiveAlgorithmOnAFreeNode. That helper still checksSuccessand the error message, and the callers still check the response's JSON. - No test, case or assertion was removed. The rename test still checks that a name-only update keeps the description.
- Other CI checks are green. API Tests was skipped, as explained above.
Minor, not blocking: the per-test object store keys are only deleted when every assertion before the delete passes, so failed runs leave GUID keys under /CI_TEST_TEMPORARY. Deleting them in a finally would keep the folder from growing.
No other repository needs an update.
Label: risk:high. The change only touches tests and is easy to revert, but risk:low still needs a passing run of the API Tests workflow on this commit (item 2) and a fix for item 1.
| if (isSuccessExpected) | ||
| { | ||
| // Under load the download url can take longer than the client polls for it, a new request can get it sooner | ||
| while (!result && DateTime.UtcNow < finish) |
There was a problem hiding this comment.
Each GetObjectStore call can take up to 5 minutes (Api.cs:1387), and finish is only checked before a call. A retry that starts at about 5 minutes can therefore end at about 10, past the per-test --blame-hang-timeout 7minutes, which kills the test host and loses the rest of the run, where master fails a single assertion at 5 minutes. Either raise the hang timeout in the workflow to cover the longest retry, or retry only after a call that failed quickly, and give the real worst case in the description.
There was a problem hiding this comment.
Done in 054d5e0: the workflow's per-test --blame-hang-timeout goes from 7 to 12 minutes. A new attempt starts only before the 6-minute mark and each call waits up to 5 minutes, so the worst case for one of these cases is about 11. I kept the retry rather than limiting it to quick failures, because a slow url is the case the retry is for. The comment by the loop and the description now give that worst case.
A retry of the download can start up to 6 minutes into the test and wait 5 more for its url, so raise the workflow's per-test hang timeout from 7 to 12 minutes instead of letting it kill the test host. Delete the object store test keys in a finally, so a failed run doesn't leave them behind. Part of #9967 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Addressed the review in 054d5e0:
|
There was a problem hiding this comment.
Approving. Both findings from my last review are resolved:
- Download retry versus hang timeout.
--blame-hang-timeoutgoes from 7 to 12 minutes, the only workflow change. That covers the worst case: a new attempt starts before the 6-minute mark andGetObjectStorewaits up to 5 minutes for its url, about 11 minutes in total. The comment by the loop and the description now give that figure. - A run of the changed workflow. The API Tests run on this head commit passed 57 of 57 (I checked the log):
ProjectTestsin parallel withObjectStoreTests, the download cases included. The tests took 9.1 min, down from 12.3. The description gives the outcome only.
The minor point is done too. Both object store key tests delete their key in a finally. On success, that second delete hits a key that's already gone. DeleteObjectStore returns an unsuccessful response there instead of throwing (Api/Api.cs:1479), so it can't fail the test.
CI: every check on the pull request branch passes. The six fail entries are the duplicate runs the extra branch push started, on the same commit. They were cancelled, not failed.
No other repository needs an update.
Label: risk:low. The change touches only tests and the API Tests workflow's timeout, so it's easy to revert. It has no effect on Lean itself, and a passing run of the changed workflow on this commit backs it.
There was a problem hiding this comment.
Approving this head commit. No blocking findings after reviewing the complete change and the earlier discussion.
The earlier requests are resolved: the workflow's hang timeout is now 12 minutes, the download retry's timing is documented, both temporary-key tests clean up in a finally, and the description includes a passing run of the changed workflow.
Verification:
- Checked the API Tests run: it ran this exact commit and passed all 57 tests, including both fixtures and the download cases. Test execution took about 9.1 minutes.
- Rebuilt the test project in Release successfully. Focused end-to-end execution of
SetObjectStoreWorksAsExpectedandDeleteObjectStoreWorksAsExpectedpassed. This was not a second full-suite run. - Checked the parallel-test isolation and retry paths. The shared-project/backtest mutations remain non-parallelizable. Concurrent same-name project creation also succeeded with distinct project IDs.
- The six checks displayed as failures are cancelled duplicate runs, not test failures; the corresponding PR-branch checks passed.
No other repository needs an update.
Label: risk:low. This is a small, reversible change confined to tests and the API Tests workflow's timeout, with no production API or engine behavior change and a passing full workflow on the reviewed commit.
Part of #9967 (stage 1 of the plan posted on the issue)
What changed and why
Speed:
ProjectTestsruns its tests in parallel. Until now they ran one at a time, about 11 of the workflow's 12.3 test minutes. The fixture is nowParallelizable(ParallelScope.All). The tests that change the sharedTestProject/TestBacktestareNonParallelizable, so no other test reads them mid-change:CRUD_ProjectFiles_Successfully,RU_ProjectNodes_Successfully,UpdateBacktestName,UpdatesBacktestTags,UpdateProjectNameAndDescription,UpdateBacktestThroughTheInterfaceKeepsTheName. So isListProjectsPagesTheAccountProjects, which reads the account's project list twice and expects the first project to still be there. Every other test creates and deletes its own project, as before.ObjectStoreTestskeeps running its tests in sequence (see below).Reliability: the fixes from the issue comment, all in the tests.
CreatesOptimization(andOptimizationTests) request 6 parallel nodes, the most the api accepts, instead of 12.SetObjectStoreWorksAsExpected/DeleteObjectStoreWorksAsExpectedeach write under a new key,/CI_TEST_TEMPORARY/<guid>, instead of the fixed/CI_TEST/Ricardoevery concurrent run shared. The delete test pauses a second between listing polls; it used to poll with no pause.UpdateProjectNameAndDescriptionrenames to a second new name instead of back to the original, which the api refused withGiven name already exist in your organization. It still checks that a name-only update keeps the description.ReadBacktestReportWaitsUntilTheReportIsGeneratedandReadBacktestOrdersReportAndChartread the report until it's generated, up to 5 minutes, instead of failing after the client's 1-minute poll. The assertions are unchanged.GetObjectStoreWorksAsExpectedask for the download again when the client's 5-minute wait for its url runs out. A new attempt can start up to 6 minutes into the test, and each call waits up to 5 minutes, so the worst case for one of these cases is about 11 minutes. To keep that from killing the test host, the workflow's per-test--blame-hang-timeoutgoes from 7 to 12 minutes (the only change to.github/workflows/api-tests.yml). On master the same case fails one assertion at 5 minutes.SetObjectStoreWorksAsExpected/DeleteObjectStoreWorksAsExpectedalso delete their key in afinally, so a failed run doesn't leave it behind.CreatesLiveAlgorithmandReadLiveInsightsWorksAsExpectedwait up to 5 minutes for a free live node and deploy on it. They retry when another run takes the node first, instead of assertingNo free Live Nodes foundat once.Two more causes found while running the suite in parallel, both already present on master:
ApiTestBase.ReloadConfigurationresets and refills the shared static configuration. Two fixtures setting up at once can collide, which fails a whole fixture'sOneTimeSetUpwithCan not add property api-url to Newtonsoft.Json.Linq.JObject. Property with the same name already exists. It now runs under a lock.*_CreatedCompiledAndBacktested_Unsuccessully("OnData")read the backtest status once after the wait. That wait stops as soon as the final statistics are in, and under load the api can report them before theRuntime Errorstatus: the test readCompleted.while the api later showedRuntime Error. The test now polls the status until it is the expected one, up to a minute.The default deadlines of
WaitForCompilerResponseandWaitForBacktestCompletiongo from 60 s to 300 s. With the tests running together, compiles and backtests can wait in the node queue, and most callers already passed 300 or 600. A deadline only matters when something is wrong: the waits return as soon as their condition holds.No test, case or assertion is removed, skipped or weakened.
Measurements
API Tests workflow on this pull request's head commit (054d5e0), run by pushing the same commit to a branch name without
/, since the workflow only runs on such pushes (run):CreatesOptimization), plus the flaky tests the issue listsThe test step is now bound by
ObjectStoreTests, which still runs its tests one after another: its"The key is not present"case took 5 min 2 s,DeleteObjectStoreWorksAsExpected1 min, and two download cases about 50 s each, about 8.6 minutes with set-up. InProjectTests, the longest tests wereReadLiveInsightsWorksAsExpected(4 min 21 s) andCreatesOptimization(3 min 45 s, now that it requests 6 nodes); the rest finished alongside them.That is one CI run. For consistency, the suite also ran locally, in the workflow's
quantconnect/lean:foundationimage with its build and test commands:ProjectTests, 4 runs in a row, in parallel as on CI: the 36 tests that could run locally passed in every run, 6.8 to 7.4 min each. The 2 report tests can't run locally, and fail there on master too.ObjectStoreTestswithout its download cases, 2 runs: 10 of 10 passed each time, about 1.1 min. The download cases ran only on CI, above.dotnet testfilter: 39,684 passed, 0 failed, 100 skipped.I left the other workflows' runs on this pull request running, since they're its CI evidence, and cancelled the duplicate runs the extra branch push started.
Left for the next stages
ObjectStoreTests, about 7 minutes.GetObjectStoreWorksAsExpected("The key is not present")can only returnfalseafter the client's 5-minute poll, since the api never fails a download job for a missing key. Shortening that needs a client-side limit on the wait (a publicApichange, a person's call) or the server reporting the job as failed.DeleteObjectStoreWorksAsExpectedwaits about a minute for the listing to drop the deleted file.ReadLiveInsightsWorksAsExpected, 4 min 15 s. Two live deployments each run a fixed 120 s; waiting on what they wait for, such as the deployment's first orders, would cut most of it.